package com.ywl.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ywl.pojo.Teacher;
import com.ywl.service.TeacherService;
import com.ywl.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author DL5O
 * @version 1.0
 */
@Api(tags = "教师控制器")
@RestController//   不是@Controller，异步Controller
@RequestMapping("/sms/teacherController")
public class TeacherController {
    @Autowired
    TeacherService teacherService;


    ///sms/teacherController/deleteTeacher
    @ApiOperation("教师信息单个或者多个批量删除")
    @DeleteMapping("/deleteTeacher")
    public Result deleteTeacher(@ApiParam("要删除的教师信息ID") @RequestBody List<Integer> ids){
        teacherService.removeByIds(ids);
        return Result.ok();
    }


    // /sms/teacherController/saveOrUpdateTeacher
    @ApiOperation("更新或者新增教师信息")
    @PostMapping("/saveOrUpdateTeacher")
    public Result saveOrUpdateTeacher(@RequestBody @ApiParam("要更新的老师信息") Teacher teacher){
        teacherService.saveOrUpdate(teacher);
        return Result.ok();
    }


    //http://localhost:9001/sms/teacherController/getTeachers/1/3
    /**
     * 教师信息分页查询
     * @param pageNo
     * @param pageSize
     * @param teacher
     * @return
     */
    @ApiOperation("分页查询教师信息")
    @GetMapping("/getTeachers/{pageNo}/{pageSize}")
    public Result getTeachers(
            @ApiParam("页码数") @PathVariable("pageNo") Integer pageNo,
            @ApiParam("页大小") @PathVariable("pageSize") Integer pageSize,
            @ApiParam("查询条件") Teacher teacher
    ) {
        //分页
        Page<Teacher> page = new Page<>(pageNo, pageSize);
        IPage<Teacher> pageRS= teacherService.getTeacherOpr(page,teacher);
        return Result.ok(pageRS);
    }

}
